<template>
    <div class="home">
        <!-- 搜索框 -->
        <van-search
            v-model="value"
            input-align="center"
            shape="round"
            background="#4fc08d"
            placeholder="输入商家、商品名称"
        />
        <!-- 轮播图 -->
        <van-swipe v-if="lunboList.length" :autoplay="3000" lazy-render class="my-swipe">
            <van-swipe-item v-for="item in lunboList" :key="item.id">
                <img :src="item.bannerUrl" />
            </van-swipe-item>
        </van-swipe>
        <!-- 轮播图 骨架屏 -->
        <van-skeleton v-else title :row="2" />
        <!-- 店铺排序 -->
        <div class="indexMain">
            <div class="title">猜你喜欢</div>
            <div class="once">
                <span class="onceli">综合排序</span>
                <span class="onceli" @click="juli">距离最近</span>
                <span class="onceli" @click="xiaoliang">销量最高</span>
                <span class="onceli">筛选</span>
            </div>
            <div class="twonce">
                <span class="twonceli">年货节热卖</span>
                <span class="twonceli">津贴联盟</span>
                <span class="twonceli">满减优惠</span>
                <span class="twonceli">品质联盟</span>
            </div>
        </div>
        <!-- 店铺列表 -->
        <div class="three" v-if="shoplist.length">
            <div class="list" v-for="(item,index) in shoplist" :key="index" @click="detail(item.mtWmPoiId)">
                <div class="left">
                    <img :src="item.picUrl" alt="" class="img2">
                </div>
                <div class="right">
                    <div class="first">{{item.name}}</div>
                    <div class="second">{{item.monthSalesTip}}</div>
                    <div class="third">{{item.minPriceTip}}</div>
                    <div class="force">{{item.shippingFeeTip}}</div>
                </div>
                <div class="box">
                    <span class="time">{{item.deliveryTimeTip}}</span>
                    <span class="gongli">{{item.distance}}</span>
                </div>
            </div>
        </div>
        <!-- 店铺列表 骨架屏 -->
        <van-skeleton v-else title :row="15" />
    </div>
</template>

<script setup>
import { onMounted,ref } from 'vue';
import { user_shouye,banner_list } from '../../api/index'
import { useRouter } from 'vue-router'

var $router = useRouter()   //获取路由管理对象

//数据
var shoplist = ref([])
var lunboList = ref([])
var value = ref()

//方法
var juli = ()=>{
    shoplist.value.sort((a,b)=>{
        return parseFloat(a.distance) - parseFloat(b.distance)
    })
}
var xiaoliang = ()=>{
    shoplist.value.sort((a,b)=>{
        return parseFloat(b.monthSalesTip.substr(2)) - parseFloat(a.monthSalesTip.substr(2))
    })
}
var detail = (id)=>{
    $router.push('/detail/'+id)
}

//挂载期
onMounted(()=>{

    user_shouye().then((res)=>{
        shoplist.value = res.data.list
        // console.log(shoplist.value);
    })

    banner_list().then((res)=>{
        lunboList.value = res.data.list
        // console.log(lunboList.value)
    })
})

</script>

<style scoped>
    .my-swipe{
        margin: 10px 0; 
        border-radius:10px ;
    }
    .my-swipe img{
        width: 100%;
    }
    .title{
        font-size: 22px;
        font-weight: 700;
    }
    .once{
        font-size: 18px;
        display: flex;
        height: 40px;
        justify-content: space-between;
    }
    .onceli{
        width: 22%;
        height: 40px;
        text-align: center;
        line-height: 40px;
    }
    .twonce{
        display: flex;
        height: 40px;
        justify-content: space-between;
    }
    .twonceli{
        width: 24%;
        height: 40px;
        text-align: center;
        line-height: 40px;
        background-color: #eee;
        border-radius: 10px;
    }
    .three{
        width: 100%;
        height: 380px;
        overflow: auto;
        margin-top: 5px;
    }
    .list{
        display: flex;
        box-sizing: border-box;
        padding: 5px;
        position: relative;
        margin-bottom: 10px;
    }
    .left{
        width: 30%;
        background-color: white;
        
    }
    .img2{
        width: 100%;
        height: 100px;
        border-radius: 10px;
    }
    .right{
        margin-top: 5px;
        margin-left: 10px;
    }
    .first{
        font-size: 16px;
        font-weight: 700;
        margin-bottom: 5px;
    }
    .second{
        font-size: 12px;
        color: rgb(78, 76, 76);
        margin-bottom: 5px;
    }
    .third{
        color: red;
        font-size: 14px;
        margin-bottom: 5px;
    }
    .fourth{
        display: flex;
        align-items: center;
        font-size: 14px;
    }
    .box{
        position: absolute;
        right:10px;
        top:60px
    }
    .time{
        margin-left: 5px;
        color: #aaa;
    }
    .gongli{
        margin-left: 13px;
        color: #aaa;
    }
</style>